<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
  *{
    margin:0;
    padding: 0;
  }
  .box{
    margin: 100px auto;
    width: 200px;
    height: 200px;
    background-color: blue;
    position: relative;
  }
  input{
    position: absolute;
    right: -50px;
  }
  .guan{
    top:50px;
  }
  .kai{
    bottom: 50px;
  }
  .bg-c{
    background-color: red;
  }
  </style>
</head>
<body>
  <div class="box" id="div">
    <input type="button" class="guan" id="off" value="关灯"/>
    <!-- <input type="button" class="kai" id="on" value="开等"/> -->
  </div>
</body>
<script>
var box3=document.getElementById('div');
var box1=document.getElementById('off');
var box2=document.getElementById('on');
// box1.onclick=function(){
//   // document.body.style.backgroundColor='red';
//   div.style.backgroundColor='orange';
// }
// box2.onclick=function(){
//   document.body.style.backgroundColor='green';
// }
// box1.onclick=function(){
//   box3.style.backgroundColor='orange';
// }
box1.onfocus=function(){
box3.classList.add('bg-c');

}
box1.onblur=function(){
box3.classList.remove('bg-c');

}
box1.onclick=function(){
box3.classList.toggle('bg-c');
}



</script>
</html>